package com.jvyou.app.ds.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.jvyou.app.common.domain.model.PageResult;
import com.jvyou.app.common.domain.model.Result;
import com.jvyou.app.common.enums.HttpCodeEnum;
import com.jvyou.app.ds.domain.dto.CoachDto;
import com.jvyou.app.ds.domain.dto.FaqCategoryDto;
import com.jvyou.app.ds.domain.entity.Coach;
import com.jvyou.app.ds.domain.entity.FaqCategory;
import com.jvyou.app.ds.service.FaqCategoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 驾校问题分类表(FaqCategory)表控制层
 *
 * @author 橘柚
 * @since 2025-04-20 12:17:22
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/faqCategory")
public class FaqCategoryController {

    private final FaqCategoryService faqCategoryService;

    @GetMapping("/list")
    @SaCheckPermission("ds:faqCategory:list")
    public Result<List<FaqCategory>> list(@ModelAttribute FaqCategoryDto faqCategoryDto) {
        return Result.success(faqCategoryService.listFaqCategory(faqCategoryDto));
    }

    @GetMapping("/page")
    @SaCheckPermission("ds:faqCategory:page")
    public Result<PageResult<FaqCategory>> page(@ModelAttribute FaqCategoryDto faqCategoryDto) {
        return Result.success(faqCategoryService.pageFaqCategory(faqCategoryDto));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    @SaCheckPermission("ds:faqCategory:get")
    public Result<FaqCategory> selectOne(@PathVariable Long id) {
        return Result.success(faqCategoryService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param faqCategory 实体对象
     * @return 新增结果
     */
    @PostMapping
    @SaCheckPermission("ds:faqCategory:insert")
    public Result<FaqCategory> insert(@RequestBody FaqCategory faqCategory) {
        boolean success = faqCategoryService.save(faqCategory);
        return success ? Result.success(faqCategory) : Result.error(HttpCodeEnum.ADD_FAIL);
    }

    /**
     * 修改数据
     *
     * @param faqCategory 实体对象
     * @return 修改结果
     */
    @PutMapping("/updateById")
    @SaCheckPermission("ds:faqCategory:update")
    public Result<Boolean> updateById(@RequestBody FaqCategory faqCategory) {
        boolean success = faqCategoryService.updateById(faqCategory);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.UPDATE_FAIL);
    }


    /**
     * 删除数据
     *
     * @param id 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/{id}")
    @SaCheckPermission("ds:faqCategory:delete")
    public Result<Boolean> delete(@PathVariable Long id) {
        boolean success = faqCategoryService.removeById(id);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.DELETE_FAIL);
    }

}

